home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1994 December / PSL Monthly Shareware CD-ROM (Public Software Library)(December 1994).bin / prgmming / dos / asm / m8087.mac < prev    next >
Text File  |  1984-08-27  |  29KB  |  823 lines

  1. ;**********************************************************************;
  2. ;                                                                      ;
  3. ;       M8087.MAC - File of macros which provide assembly level        ;
  4. ;                   software support for use of 8087 NDP with          ;
  5. ;                   the IBM personal computer.                         ;
  6. ;                                                                      ;
  7. ;**********************************************************************;
  8.  
  9. if1     ; do not include this file in any output listing
  10.  
  11. ;**********************************************************************;
  12. ;                                                                      ;
  13. ;       ESC_REG - "REG" parameter specifies ESC value.  Issue proper   ;
  14. ;                 ESC sequence depending on REG value.  PARAM is a     ;
  15. ;                 6-bit parameter whose upper 3-bits make up the       ;
  16. ;                 "xxx" bits in the ESC opcode (11011xxx) and lower    ;
  17. ;                 3-bits make up "yyy~ bits in source byte following   ;
  18. ;                 (using standard "mod" and "r/m" designators define   ;
  19. ;                 byte as "modyyyr/m").                                ;
  20. ;                                                                      ;
  21. ;**********************************************************************;
  22.  
  23. ESC_REG macro PARAM,REG
  24.         ;
  25.         ; We need to determine what "reg" field assignment correspnds with
  26.         ; the current value of REG.  This is used as the source for the
  27.         ; ESC operation.  PARAM is used directly in the ESC call.
  28.         ;
  29.         ife REG ; Decrement until REG = 0, then issue ESC sequence
  30.           ESC PARAM,AX          ; AX = 000b (see operand summary for 8088)
  31.         else
  32.           REG = REG - 1
  33.           ife REG
  34.             ESC PARAM,CX                ; CX = 001b
  35.           else
  36.             REG = REG - 1
  37.             ife REG
  38.               ESC PARAM,DX              ; DX = 010b
  39.             else
  40.               REG = REG - 1
  41.               ife REG
  42.                 ESC PARAM,BX            ; BX = 011b
  43.               else
  44.                 REG = REG - 1
  45.                 ife REG
  46.                   ESC PARAM,SP          ; SP = 100b
  47.                 else
  48.                   REG = REG - 1
  49.                   ife REG
  50.                     ESC PARAM,BP        ; BP = 101b
  51.                   else
  52.                     REG = REG - 1
  53.                     ife REG
  54.                       ESC PARAM,SI      ; SI = 110b
  55.                     else                ; If REG >= 7, assume 7
  56.                       ESC PARAM,DI      ; DI = 111b
  57.                     endif
  58.                   endif
  59.                 endif
  60.               endif
  61.             endif
  62.           endif
  63.         endif
  64. endm    ; Done with ESC_REG macro
  65.  
  66. ;**********************************************************************;
  67. ;                                                                      ;
  68. ;       CHECK_ST - Inputs parameter "ST(i)" and returns with REG=i     ;
  69. ;                                                                      ;
  70. ;**********************************************************************;
  71.  
  72. CHECK_ST macro P_ST
  73.         REG = -1                        ; Assume no match is found
  74.         ifidn <&P_ST>,<ST(0)>           ; Is i=0?
  75.           REG = 0
  76.         endif
  77.         ifidn <&P_ST>,<ST(1)>
  78.           REG = 1
  79.         endif
  80.         ifidn <&P_ST>,<ST(2)>
  81.           REG = 2
  82.         endif
  83.         ifidn <&P_ST>,<ST(3)>
  84.           REG = 3
  85.         endif
  86.         ifidn <&P_ST>,<ST(4)>
  87.           REG = 4
  88.         endif
  89.         ifidn <&P_ST>,<ST(5)>
  90.           REG = 5
  91.         endif
  92.         ifidn <&P_ST>,<ST(6)>
  93.           REG = 6
  94.         endif
  95.         ifidn <&P_ST>,<ST(7)>
  96.           REG = 7
  97.         endif
  98.         ifidn <&P_ST>,<st(0)>           ; Is i=0?
  99.           REG = 0
  100.         endif
  101.         ifidn <&P_ST>,<st(1)>
  102.           REG = 1
  103.         endif
  104.         ifidn <&P_ST>,<st(2)>
  105.           REG = 2
  106.         endif
  107.         ifidn <&P_ST>,<st(3)>
  108.           REG = 3
  109.         endif
  110.         ifidn <&P_ST>,<st(4)>
  111.           REG = 4
  112.         endif
  113.         ifidn <&P_ST>,<st(5)>
  114.           REG = 5
  115.         endif
  116.         ifidn <&P_ST>,<st(6)>
  117.           REG = 6
  118.         endif
  119.         ifidn <&P_ST>,<st(7)>
  120.           REG = 7
  121.         endif
  122.         ;
  123.         ; If i not between 0 or 7, see if actually an
  124.         ; "ST(i)" or "ST(I)" string, indicating use of
  125.         ; top of stack element
  126.         ;
  127.         ifidn <&P_ST>,<ST(i)>
  128.           REG = 0
  129.         endif
  130.         ifidn <&P_ST>,<ST(I)>
  131.           REG = 0
  132.         endif
  133.         ifidn <&P_ST>,<st(i)>
  134.           REG = 0
  135.         endif
  136.         ifidn <&P_ST>,<st(I)>
  137.           REG = 0
  138.         endif
  139. endm
  140.  
  141.  
  142. ;**********************************************************************;
  143. ;*                                                                     ;
  144. ;*      CHK_CONC - Simple macro that will automatically insert         ;
  145. ;*                 WAIT statements AFTER every 8087 instruction        ;
  146. ;*                 which accesses CPU main memory.  If variable        ;
  147. ;*                 "AUTOSYNC" <> 0, then these WAITs will be           ;
  148. ;*                 inserted (providing no concurrency but relieving    ;
  149. ;*                 the programmer from worrying about synchronizing    ;
  150. ;*                 data references.  If the user program sets          ;
  151. ;*                 AUTOSYNC to a zero value, then no WAITs are         ;
  152. ;*                 inserted after the instructions and it is           ;
  153. ;*                 the user's responsibility to ensure synchro-        ;
  154. ;*                 nization.                                           ;
  155. ;*                                                                     ;
  156. ;**********************************************************************;
  157.  
  158. CHK_CONC macro
  159.  
  160.         if AUTOSYNC
  161.                   WAIT                  ; Automatic syncronization
  162.         endif
  163. endm
  164.  
  165.  
  166.  
  167. ;**********************************************************************;
  168. ;                                                                      ;
  169. ;       CHOOSE_4 - Determine which of four parameters (XXX1 to XXX4)   ;
  170. ;                  should be used in ESC sequence, depending on P1     ;
  171. ;                  and P2 values.  P2 and P2 are parameters passed     ;
  172. ;                  by user in macro call.  XXX1 to XXX4 are macro-     ;
  173. ;                  dependent parameters tacked on to the call to       ;
  174. ;                  CHOOSE_4 by the specific 8087 macro called by the   ;
  175. ;                  user code.                                          ;
  176. ;                                                                      ;
  177. ;**********************************************************************;
  178.  
  179. CHOOSE_4 macro P1,P2,XXX1,XXX2,XXX3,XXX4
  180.  
  181.         ; Initialize variables
  182.         ZERO = 0
  183.         NOTZERO = 0
  184.         REG = 0
  185.         ;
  186.         ; If user passed no parameters, (P1 and P2 are "blank") then
  187.         ; issue a call to ESC_REG macro to set up proper ESC sequence.
  188.         ; An arithmetic instruction with no operands is identical to the
  189.         ; same instruction with the operand form "ST(1),ST".
  190.         ; Example: "FDIV" - Divides second element of stack by first and
  191.         ;                   places result in second element on stack.
  192.         ;
  193.         ifb <P1>
  194.                   REG = 1
  195.                   ESC_REG XXX1,REG
  196.         else
  197.         ;
  198.         ; Check to see if first parameter (P1) passed by user is "ST".
  199.         ; If yes, indecates that second parameter (P2) is of form "ST(i)"
  200.         ; so use CHECK_ST macro to determine 'i'.  Then call ESC_REG macro
  201.         ; to issue ESC sequence.
  202.         ; Example: "FADD ST,ST(4)" - Adds register four (fifth element on
  203.         ;                            8087 stack) to top element and leaves
  204.         ;                            result on top of stack.
  205.         ;
  206.         ifidn <P1>,<ST>
  207.           CHECK_ST P2
  208.           ZERO = REG + 1
  209.           ife ZERO
  210.             REG = 1
  211.           endi